/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 */
#ifndef TYPICAL_PARAM_CHECK_H
#define TYPICAL_PARAM_CHECK_H
#include "interface_hccl.h"
namespace hccl {

HcclResult CheckDataType(const HcclDataType dataType)
{
    if ((dataType >= HCCL_DATA_TYPE_RESERVED) || (dataType < HCCL_DATA_TYPE_INT8)) {
        HCCL_ERROR("[Check][DataType]errNo[0x%016llx] data type[%s] not supported",
            HCOM_ERROR_CODE(HCCL_E_NOT_SUPPORT), GetDataTypeEnumStr(dataType).c_str());
        return HCCL_E_NOT_SUPPORT;
    }
    return HCCL_SUCCESS;
}

HcclResult CheckCount(const u64 count)
{
    if (count > SYS_MAX_COUNT) {
        HCCL_ERROR("[Check][Count]errNo[0x%016llx] count[%llu] is invalid(bigger than MAX count[%llu])",
            HCOM_ERROR_CODE(HCCL_E_PARA), count, SYS_MAX_COUNT);
        return HCCL_E_PARA;
    }
    return HCCL_SUCCESS;
}

HcclResult CheckParam(void* buf, uint64_t count, HcclDataType dataType,
    AscendSendRecvInfo* sendRecvInfo, aclrtStream stream)
{
    CHK_PTR_NULL(buf);
    CHK_RET(CheckCount(count));
    CHK_RET(CheckDataType(dataType));
    CHK_PTR_NULL(sendRecvInfo);
    CHK_PTR_NULL(stream);
    CHK_PTR_NULL(sendRecvInfo->localQPinfo);

    CHK_PTR_NULL(sendRecvInfo->localWindowMem);
    CHK_PTR_NULL(sendRecvInfo->remoteWindowMem);

    CHK_PTR_NULL(sendRecvInfo->localSyncMemPrepare);
    CHK_PTR_NULL(sendRecvInfo->localSyncMemDone);
    CHK_PTR_NULL(sendRecvInfo->localSyncMemAck);

    CHK_PTR_NULL(sendRecvInfo->remoteSyncMemPrepare);
    CHK_PTR_NULL(sendRecvInfo->remoteSyncMemDone);
    CHK_PTR_NULL(sendRecvInfo->remoteSyncMemAck);

    CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->localWindowMem->addr));
    CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->remoteWindowMem->addr));

    CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->localSyncMemPrepare->addr));
    CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->localSyncMemDone->addr));
    CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->localSyncMemAck->addr));

    CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->remoteSyncMemPrepare->addr));
    CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->remoteSyncMemDone->addr));
    CHK_PTR_NULL(reinterpret_cast<void*>(sendRecvInfo->remoteSyncMemAck->addr));
    return HCCL_SUCCESS;
}
}  // namespace hccl
#endif